package nxu.controller;

import nxu.entity.UserLog;
import nxu.service.UserLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class UserLogController {

    @Autowired
    UserLogService userLogService;

    @PostMapping("/getUserLog")
    @ResponseBody
    public String getUserLog(Model model, String phone) {
        List<UserLog> userLogsList = userLogService.getUserLog(phone);
        ArrayList<String> info  = new ArrayList<>();
        if(userLogsList.isEmpty()) {
            info.add("没有获取到数据！");
            model.addAttribute("info", info);
        } else {
            model.addAttribute("userLog", userLogsList);
        }
        return "/webpage/majiang";
    }

}
